import sys
from wiget2 import Ui_Form
from PyQt5 import QtCore, QtGui, QtWidgets
from pydocument import RC4,forkComb,selfprint,ceaser,Playfair,frequency,DES
import time

class MyPyQT_Form(QtWidgets.QWidget,Ui_Form):
    def __init__(self):
        super(MyPyQT_Form,self).__init__()
        self.setupUi(self)

    #实现pushButton_click()函数
    def push1_1(self):
        msg = self.text_input.toPlainText()
        code = ""#self.textEdit.toPlainText()
            #list('afgaZzABb')
        offset = 3
        final = ceaser.caesar(msg,code, offset, action='encode')
        final1 = "".join(final)
        self.text_output.setPlainText(final1)

    def push1_2(self):
        msg = ""
        a = self.text_input.toPlainText()
        code = list(a)
        #
        # list('afgaZzABb')
        offset = 3
        final = ceaser.caesar(code=code, offset=offset, action='decode')
        final1 = "".join(final)
        self.text_output.setPlainText(final1)

    def push1_3(self):
        #实验1Playfair加密
        msg=self.text_input.toPlainText()#输入的待加密信息
        key = self.text_keys.toPlainText()#输入的密钥
        cipher = Playfair.Encrypt(msg,key)
        self.text_output.setPlainText(cipher)

    def push1_4(self):
        #实验1Playfair解密
        msg=self.text_input.toPlainText()#输入的待解密信息
        key = self.text_keys.toPlainText()#输入的密钥
        cipher = Playfair.Decrypt(msg,key)
        self.text_output.setPlainText(cipher)

    def push1_5(self):
        #实验1频率统计
        text1,text2=frequency.frequency()
        print(text1)
        print(text2)
        self.text_input.setPlainText(text1)
        self.text_output.setPlainText(text2)

    def push1_6(self):
        #实验1代换表
        text1,text2=frequency.show()
        self.text_input.setPlainText(text1)
        self.text_output.setPlainText(text2)

    def push2_2(self):
        # 实验2 RC4解密
        msg = self.text_input.toPlainText()
        key = self.text_keys.toPlainText()

        cipher = RC4.getmode2(msg, key)
        self.text_output.setPlainText(cipher)

    def push2_1(self):
        #实验2 RC4加密部分
        msg=self.text_input.toPlainText()#输入的待加密信息
        key = self.text_keys.toPlainText()#输入的密钥
        cipher = RC4.getmode1(msg,key)
        self.text_output.setPlainText(cipher)

    def push3(self):
        while True:
            forkComb.run()

    def push4(self):
        content = selfprint.selfprint()
        self.text_output.setPlainText(content)
        while True:
            self.text_output.insertPlainText(content)
            time.sleep(1500)

    def push7_1(self):
        encryption = self.text_input.toPlainText()#输入的待加密信息
        key = self.text_keys.toPlainText()  # 输入的密钥
        decryption = DES.Encryption(encryption,key)
        self.text_output.setPlainText(decryption)

    def push7_2(self):
        decryption = self.text_input.toPlainText()  # 输入的待加密信息
        key = self.text_keys.toPlainText()  # 输入的密钥
        incryption = DES.Decryption(decryption, key)
        self.text_output.setPlainText(incryption)


if __name__ == '__main__':
    QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
    app = QtWidgets.QApplication(sys.argv)
    my_pyqt_form = MyPyQT_Form()
    my_pyqt_form.setWindowOpacity(0.9)
    my_pyqt_form.show()
    sys.exit(app.exec_())